﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using LitJson;

public class Login : MonoBehaviour {

    public static Login Instance;

    public InputField inputName;

    public InputField inputPassword;


    void Awake()
    {
        Instance = this;

    }

    void OnEnable()
    {
        NotficationCenter.Instance.AddNotificationEvent(ClientPoll.pollEvent.Login_Back_Event.ToString(), LoginBack);
    }

    void OnDisable()
    {
        NotficationCenter.Instance.RemoveNotificationEvent(ClientPoll.pollEvent.Login_Back_Event.ToString(), LoginBack);
    }

   public void LoginBack(Notification node)
    {
        Debug.LogError("登录返回 ====>" + (string)node.data);
        //StartUIManager.Instance.LoginUIShow();
        Global.Instance.loadName = "hall";
        Application.LoadLevel("load");
    }

 
    

    public void LoginCliecked()
    {
        if (GetName == "" || GetPassword == "")
        {
            Debug.LogError("请输入完全再登录...");
            return;
        }
        //Debug.LogError("11111111111"+ GetName +">>>>>>" + GetPassword);
        JSONClass jd = new JSONClass();
        jd["cmd"] = ((int)ClientPoll.pollEvent.Login_Back_Event).ToString();
        jd["name"] = GetName;
        jd["password"] = GetPassword;
        Debug.LogError("登录请求=============>>>" + jd.ToString());
      //  ClientTcp.Instance.SendMessage(jd.ToString());
       
    }
	

    public string GetName
    {
        get
        {
            return inputName.text;
        }
    }


    public string GetPassword
    {
        get
        {
            return inputPassword.text;
        }
    }

}
